#! /bin/bash
kv4cj_path=$(cd `dirname $0`; pwd)
#kv4cj_path=$(pwd)


# check libcore.so
if [ ! -d "${kv4cj_path}/lib/" ];then
    mkdir ${kv4cj_path}/lib
    echo "Please copy libcore.so to the folder ${kv4cj_path}/lib."
    exit 1
fi

if [ ! -f "${kv4cj_path}/lib/libcore.so" ];then
    echo "Please copy libcore.so to the folder ${kv4cj_path}/lib."
    exit 1
fi

# libmymmkv.so
cd ${kv4cj_path}/mmkv_cpp
if [ -f "Makefile" ];then
    make clean
fi

# "/usr1/ohos/native/llvm/bin" 为 ohos 编译器路径，请自行修改
# "/usr1/ohos/native/sysroot" 为 ohos sysroot 路径，请自行修改
./configure --cxx="/usr1/ohos/native/llvm/bin/clang++" --cross-prefix="/usr1/ohos/native/llvm/bin/llvm-" \
--target=aarch64-linux-ohos \
--cxxflags="--sysroot=/usr1/ohos/native/sysroot"
make

# kv4cj
cd  ${kv4cj_path}/
echo start build kv4cj
cjpm build -V --target=aarch64-linux-ohos
cp ${kv4cj_path}/lib/*.so ${kv4cj_path}/target/aarch64-linux-ohos/release/kv4cj/
echo end build kv4cj
